package main

import (
	"flag"
	"github.com/golang/glog"
	"learning_go/big_homework/homework_1/web"
	"log"
	"net/http"
	"os"
)

/**
http server的启动入口
1. 接收客户端 request，并将 request 中带的 header 写入 response header
2. 读取当前系统的环境变量中的 VERSION 配置，并写入 response header
3. Server 端记录访问日志包括客户端 IP，HTTP 返回码，输出到 server 端的标准输出
4. 当访问 localhost/healthz 时，应返回200
*/
func main() {
	envVersion := os.Getenv("VERSION")
	if envVersion == "" {
		os.Setenv("VERSION", "1.0.0")
	}
	flag.Set("v", "4")
	glog.V(3).Info("Starting http server...")
	//这里必须放到http.ListenAndServe之前，否则访问不到.访问别的函数需要使用包名而不是文件名。例如：web.WriteHeaderToResponse
	http.HandleFunc("/writeHeaderToResponse", web.WriteHeaderToResponse)
	http.HandleFunc("/setOSVersion", web.SetOSVersion)
	http.HandleFunc("/gerIPAndStatusCode", web.GerIPAndStatusCode)
	http.HandleFunc("/healthz", web.SetResponseStatusCode)

	err := http.ListenAndServe(":8080", nil)

	if err != nil {
		log.Println("the  http server is  start......")
	}

}
